package edu.com.wjt219971332.service.impl;

import edu.com.wjt219971332.entity.Audiencevote;
import edu.com.wjt219971332.dao.AudiencevoteDao;
import edu.com.wjt219971332.service.AudiencevoteService;
import org.aspectj.lang.annotation.After;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;


@Service
public class AudiencevoteServiceImpl implements AudiencevoteService {
    @Autowired
    private AudiencevoteDao audiencevoteDao;


    @Override
    public Audiencevote queryById(Integer uservoteid) {
        return this.audiencevoteDao.queryById(uservoteid);
    }


    @Override
    public Page<Audiencevote> queryByPage(Audiencevote audiencevote, PageRequest pageRequest) {
        long total = this.audiencevoteDao.count(audiencevote);
        return new PageImpl<>(this.audiencevoteDao.queryAllByLimit(audiencevote, pageRequest), pageRequest, total);
    }


    @Override
    public int insert(Audiencevote audiencevote) {
        return  this.audiencevoteDao.insert(audiencevote);
    }


    @Override
    public int update(Audiencevote audiencevote) {
        return this.audiencevoteDao.update(audiencevote);
    }

    @Override
    public boolean deleteById(Integer uservoteid) {
        return this.audiencevoteDao.deleteById(uservoteid) > 0;
    }

    @Override
    public Audiencevote weiyi(Integer userid, Integer competitionid) {
        return audiencevoteDao.weiyi(userid, competitionid);
    }

    @Override
    public int countvote(Integer competitionid, Integer singerid) {
        return this.audiencevoteDao.countvote(competitionid, singerid);
    }

    @Override
    public boolean deleteByuserid(Integer userid, Integer competitionid) {
        return this.audiencevoteDao.deleteByuserid(userid, competitionid) > 0;
    }
}
